<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugs/webuploader/webuploader.css">
<div class="modal fade" id="create-book-referral-link-modal">
	<div class="modal-dialog" role="document" style="width:1200px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
						aria-hidden="true">×</span></button>
				<span style="font-size: 20px;"><span id="referralname_book_id">增加</span></span>
			</div>
			<div class="modal-body">
				<div data-bind="visible: loading" class="loading-panel" style="display: none;">
					<i class="fa fa-spin fa-spinner"></i>
				</div>
				<form class="form-horizontal modelform2">
					<input type="hidden" name="id" id="createspreadbook_id">

					<div class="form-group">
						<label class="control-label col-sm-1"><span class="required">*</span> 书名名称</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" maxlength="100" name="title" id="title"
								placeholder="">
						</div>
					</div>


					<!-- <input type="hidden" name="name" value="其它"> -->
					<div class="form-group">
						<label class="control-label col-sm-1"><span class="required">*</span> 频道</label>
						<div class="col-sm-6">
							<label class="radio-inline">
								<input type="radio" checked="true" name="name" id="name" value="男频" />
								<span>男频</span>
							</label>
							<label class="radio-inline">
								<input type="radio" name="name" value="女频" />
								<span>女频</span>
							</label>

						</div>
					</div>

					<div class="form-group">
						<label class="control-label col-sm-1">排序</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" maxlength="100" name="sort" id="sort"
								placeholder="">
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-1">平台</label>
						<div class="col-sm-6">
							<select name="paltform" id="paltform" class="selectpicker form-control">
								<option value="百度" selected>百度</option>
								<option value="知乎">知乎</option>
								<option value="抖音">抖音</option>
								<option value="微博">微博</option>
								<option value="腾讯">腾讯</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-1">ROI</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" maxlength="100" name="roi" id="roi" placeholder="">
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-1">总ROI</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" maxlength="100" name="roi_count" id="roi_count"
								placeholder="">
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-1">上传原文</label>
						<div class="col-sm-11">
							<div>
								<div class="picker_button" id="upload_sample">
									<span>上传文件</span>
								</div>
								<span>(请上传.txt文件，可重复批量上传)</span>
								<input type="hidden" id="sample_path" name="sample_path" class="file_path">
								<input type="hidden" id="sample_name" name="sample_name">
							</div>
							<div id="sampleList" class="upload-file-list-info"></div>
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-1">上传标本</label>
						<div class="col-sm-11">
							<div>
								<div class="picker_button" id="upload_text">
									<span>上传文件</span>
								</div>
								<span>(请上传.txt文件)</span>
								<input type="hidden" id="text_path" name="file_path" class="text_path">
								<input type="hidden" id="text_name" name="file_name">
							</div>
							<div id="textList_ebook" class="upload-file-list-info"></div>
						</div>
					</div>
					<style>
						.nameList {display: flex;}
						.nameList input {
							width: 7.5%;
							margin-right: 8px;
							margin-bottom: 10px;
						}
					</style>
					<div class="form-group">
						<label class="control-label col-sm-1">名字</label>
						<div class="col-sm-11 nameList last">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
							<input type="text" class="form-control" name="role_name" autocomplete="false" value="">
						</div>
						
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="createreferral_book_id" class="btn btn-primary ">提交</button>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.custom.js"></script>
<script>
	(function (window, $) {
		$.fn.serializeJson = function () {
			var serializeObj = {};
			var array = this.serializeArray();
			var str = this.serialize();
			$(array).each(
				function () {
					if (serializeObj[this.name]) {
						if ($.isArray(serializeObj[this.name])) {
							serializeObj[this.name].push(this.value);
						} else {
							serializeObj[this.name] = [
								serializeObj[this.name], this.value];
						}
					} else {
						serializeObj[this.name] = this.value;
					}
				});
			return serializeObj;
		};
	})(window, jQuery);
	$(function () {
		$('#create_book_id').on('click', function () {
			var $modal = $('#create-book-referral-link-modal');
			$modal.on('shown.bs.modal', function () {
				$('#upload_text').html('<div>上传文件</div>')
				$("#upload_text").SentUploader({
					server:"{:url('Upload/Uploadtxt')}",
					fileNumLimit:1,
					hiddenName: 'text_path',
					hiddenFileName: 'text_name',
					listName: 'textList_ebook',
					hiddenValType:2,
					fileSingleSizeLimit:50*1024*1024,
				});
				$('#upload_sample').html('<div>上传文件</div>')
				$("#upload_sample").SentUploader({
					server:"{:url('Upload/Uploadtxt')}",
					fileNumLimit:100,
					hiddenName: 'sample_path',
					hiddenFileName: 'sample_name',
					listName: 'sampleList',
					hiddenValType:2,
					fileSingleSizeLimit:50*1024*1024,
				});
			})
			$modal.modal({ backdrop: 'static', keyboard: false })
		});
		$("#createreferral_book_id").on('click', function () {
			var data = $('.modelform2').serializeJson();
			let params = ['name', 'title']
			for (var i = 0; i < params.length; i++) {
				if (!data[params[i]]) {
					updateAlert("必填参数不能为空", 'danger');
					return false;
				}
			}
			var url = "{:url('adsmaterialbook/add')}";
			$.ajax({
				type: "POST",
				url: url,
				data: data,
				dataType: "json",
				success: function (data) {
					if (data.code == 1) {
						updateAlert(data.msg, 'success');
						setTimeout(function () {
							window.location.reload();
						}, 1500);
					} else {
						updateAlert("添加，" + data.msg, 'danger');
					}
				},
				error: function (e) {
					console.log(e.status);
					console.log(e.responseText);
				}
			})
		});
	});
	var json;
	function editreferral_book_id(ee) {
		var jsonStr = $(ee).attr('data-json');
		var $modal = $('#create-book-referral-link-modal');
		$modal.on('show.bs.modal', function () {
			$("#referralname_book_id").html("修改");
			$("#createreferral_book_id").html("修改");
			json = eval("(" + jsonStr + ")");
			console.log(json)
			$('#createspreadbook_id').val(json.id);
			$('#title').val(json.title);
			$('#sort').val(json.sort);
			$('#roi').val(json.roi?.百度.roi);
			$('#roi_count').val(json.roi?.百度.roi_count);
			$("input:radio[name=name][value=" + json.name + "]").attr("checked", true);
			// $("select[name=paltform]").selectpicker('val', [paltform]);
			$('#upload_text').html('<div>上传文件</div>')
			$("#upload_text").SentUploader({
				server:"{:url('Upload/Uploadtxt')}",
				fileNumLimit:1,
				hiddenName: 'text_path',
				hiddenFileName: 'text_name',
				listName: 'textList_ebook',
				hiddenValType:2,
				fileSingleSizeLimit:50*1024*1024,
			});
			$('#upload_sample').html('<div>上传文件</div>')
			$("#upload_sample").SentUploader({
				server:"{:url('Upload/Uploadtxt')}",
				fileNumLimit:100,
				hiddenName: 'sample_path',
				hiddenFileName: 'sample_name',
				listName: 'sampleList',
				hiddenValType:2,
				fileSingleSizeLimit:50*1024*1024,
			});
		});
		$modal.on('hide.bs.modal', function () {
			window.location.reload();
		})
		$modal.modal({ backdrop: 'static', keyboard: false })
	}
	$("#paltform").on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
		let now_value = json.roi[$(this).children()[clickedIndex].text]
		if (now_value) {
			$('#roi').val(now_value.roi);
			$('#roi_count').val(now_value.roi_count);
		} else {
			$('#roi').val(0);
			$('#roi_count').val(0);
		}
	});
	
</script>